package com.hmall.user.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class Myintercrptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String userId = request.getHeader("authorization");
        log.info("====拦截到请求头===="+userId);
        System.out.println("userId = " + userId);
        ThreadLocal<Object> threadLocal = new ThreadLocal<>();
        if (StringUtils.isNotEmpty(userId)){
            threadLocal.set(userId);
        }
        return true;
    }

}
